package b;

import t1.IAdd;

/**
 * Created by Administrator on 2018/1/20.
 */
public class Multirun implements Runnable {

    public void run() {
        try {
            while (true) {
                // 每次都创建出一个新的类加载器e:\code\workspace\testJar\bin\
                // class需要放在自己package名字的文件夹下   file:/F:/workspace/ideawp/hotLoadClassDemon/target/hotLoadClass-1.0-SNAPSHOT.jar
                String url = "F:\\workspace\\ideawp\\hotLoadClassDemon\\target\\classes";
                CustomClassLoader cl = new CustomClassLoader(url, new String[] { "t1.Add" });
                Class cls = cl.loadClass("t1.Add");
//                Object foo = cls.newInstance();
//                Method m = foo.getClass().getMethod("Output", new Class[] {});
//                m.invoke(foo, new Object[] {});

                System.out.println("loadclass :"+cls);
                IAdd add2 = (IAdd) cls.newInstance();
                System.out.println(add2.add(1,2));

                Thread.sleep(2000);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
